define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-edit").data("area",["1000px","600px"]);//顶部编辑按钮

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/storekongjian/index' + location.search,
                    // add_url: 'store/store/add',
                    // edit_url: 'store/store/edit',
                    // del_url: 'store/store/del',
                    // multi_url: 'store/store/multi',
                    // import_url: 'store/store/import',
                    table: 'store',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        // {field: 'type', title: __('Type'),visible:false},
                        {field: 'type', title: __('类型'), searchList: {"1":__('中心'),"2":__('空间')}, formatter: Table.api.formatter.normal, operate: false},
                        // {field: 'type_text', title: '类型'},
                        {field: 'store_name', title: '中心/空间名称', operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'province', title: __('Province'), operate: false},
                        // {field: 'city', title: __('City'), operate: false},
                        // {field: 'area', title: __('Area'), operate: false},
                        //{field: 'address', title: __('Address'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'realname', title: __('Realname'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'tel', title: __('Tel'), operate: false},
                        //{field: 'contact_tel', title: __('Contact_tel'), operate: false},
                        //{field: 'bank_idcard', title: __('Bank_idcard'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'idcard_z', title: __('Idcard_z'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'idcard_f', title: __('Idcard_f'), operate: false},
                        //{field: 'id_card_valid_start_time', title: __('Id_card_valid_start_time'), operate: 'LIKE'},
                        //{field: 'id_card_valid_time', title: __('Id_card_valid_time'), operate: 'LIKE'},
                        //{field: 'id_card_arddress', title: __('Id_card_arddress'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'zizhi', title: __('Zizhi'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'zz_num', title: __('Zz_num'), operate: 'LIKE'},
                        //{field: 'merchant_name', title: __('Merchant_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'subject_type', title: __('Subject_type'), searchList: {"1":__('Subject_type 1'),"2":__('Subject_type 2')}, formatter: Table.api.formatter.normal},
                        //{field: 'license_address', title: __('License_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'period_begin', title: __('Period_begin'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'period_end', title: __('Period_end'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'business_time', title: '营业时间', operate: false},

                        //{field: 'edit_time', title: __('Edit_time'), operate: 'LIKE'},
                        //{field: 'lat', title: __('Lat'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'lng', title: __('Lng'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'password', title: __('Password'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_ban', title: '是否禁用', searchList: {"0":__('Is_ban 0'),"1":__('Is_ban 1')}, formatter: Table.api.formatter.normal, operate: false},
                        //{field: 'is_del', title: __('Is_del'), searchList: {"0":__('Is_del 0'),"1":__('Is_del 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'authen_time', title: __('Authen_time'), operate: 'LIKE'},
                        // {field: 'bank_id', title: __('Bank_id')},
                        // {field: 'bank_province', title: __('Bank_province'), operate: 'LIKE'},
                        // {field: 'bank_area', title: __('Bank_area'), operate: 'LIKE'},
                        // {field: 'bank_no', title: __('Bank_no'), operate: 'LIKE'},
                        // {field: 'account_name', title: __('Account_name'), operate: 'LIKE'},
                        // {field: 'store_qr_code', title: __('Store_qr_code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'applyment_id', title: __('Applyment_id'), operate: 'LIKE'},
                        // {field: 'bank_account_type', title: __('Bank_account_type'), operate: 'LIKE'},
                        // {field: 'sub_mchid', title: __('Sub_mchid'), operate: 'LIKE'},
                        // {field: 'xvstatus', title: __('Xvstatus'), searchList: {"0":__('Xvstatus 0'),"1":__('Xvstatus 1'),"2":__('Xvstatus 2'),"3":__('Xvstatus 3'),"4":__('Xvstatus 4')}, formatter: Table.api.formatter.status},
                        // {field: 'xv_reamrk', title: __('Xv_reamrk'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'start_time', title: '合同开始日期', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: '合同结束日期', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'add_time', title: '创建时间', operate: false},
                        //{field: 'promotion_type', title: __('Promotion_type'), searchList: {"0":__('Promotion_type 0'),"1":__('Promotion_type 1'),"2":__('Promotion_type 2'),"3":__('Promotion_type 3')}, formatter: Table.api.formatter.normal},
                        //{field: 'promotion_id', title: __('Promotion_id')},
                        //{field: 'promotion_money', title: __('Promotion_money'), operate:'BETWEEN'},
                        // {field: 'admin.username', title: __('Admin.username'), operate: 'LIKE'},
                        // {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
                        // {field: 'admin.mobile', title: __('Admin.mobile'), operate: 'LIKE'},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            //操作栏编辑按钮大小
            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["100%","100%"]);
            });


            //分配到中心
            $(document).on('click', '.btn-fenpei', function () {
                var ids = Table.api.selectedids(table);
                if (ids.length == 0) {
                    Toastr.error('请选择要分配的空间');
                    return false;
                }
                console.log(ids);
                let html = Template('tpl-all-pass', {});
                layer.open({
                    type: 1,
                    skin: 'layui-layer-demo', //样式类名
                    title: '分配到中心',
                    anim: 2,
                    area: ['400px', '300px'],
                    shadeClose: 1, //开启遮罩关闭
                    content: html,
                    btn: ['确认', '取消'],
                    zIndex: 10,
                    yes: function (index) {
                        let cid = ($('#c-c_id').val()).trim();

                        if (!cid) {
                            Toastr.error('请选择中心');
                            return;
                        }

                        $.post('store/storekongjian/fenpeiCenter', {
                            cid:cid,store_ids:ids.join(',')
                        }, function (res) {
                            if (res.code == 1) {
                                table.bootstrapTable('refresh', {pageNumber: 1});
                                Toastr.success(res.msg);
                                Layer.close(index);
                            } else {
                                Toastr.error(res.msg);
                            }
                        })

                    },
                    success: function (layero, index) {
                        Form.api.bindevent($('.shipper'));
                    }
                });
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));

            }
        }
    };
    return Controller;
});
